package com.example.demo1.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.demo1.common.Result;
import com.example.demo1.entity.Project;
import com.example.demo1.entity.Share;
import com.example.demo1.service.ShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("share")
public class ShareController {
    @Autowired
    private ShareService shareService;

    @PostMapping("/add")
    public Result add(@RequestBody Share share) {
        try {
            shareService.addShare(share);
            return Result.success();
        } catch (Exception e) {
            return Result.fail(e.toString());
        }
    }

    @PostMapping("/list/{currentPage}/{pageSize}")
    public Result getShare(@PathVariable int currentPage,
                             @PathVariable int pageSize,
                             @RequestBody Share share){
        IPage<Share> IPageShare=shareService.getShareList(currentPage, pageSize, share);
        return Result.success(IPageShare);
    }

    @GetMapping("/getAll")
    public Result getAllShares(){
        return Result.success(shareService.getAllShares());
    }

}
